package com.example.administrator.yuejian_15.activity;

import android.app.ProgressDialog;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.media.MediaPlayer;
import android.net.Uri;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;

import com.example.administrator.yuejian_15.R;
import com.example.administrator.yuejian_15.service.Service;


public class JlbSpInfoActivity extends BaseActivity implements View.OnClickListener {
    ImageView spinfo_fh;
    VideoView spinfo_sp;
    TextView spinfo1,spinfo2,spinfo3;
    String jlbvname,jlbvnames,jlbvtime,jlbjlname;

    private VideoView  videoView;
    private String path="";
    private String BASEURL="http://amicool.neusoft.edu.cn/";
    private ProgressDialog dialog;

    @Override
    void initView() {
        setLayout_file(R.layout.activity_jlb_sp_info);
        spinfo_fh = (ImageView)findViewById(R.id.spinfo_fh);
        //spinfo_sp = (VideoView)findViewById(R.id.spinfo_sp);
        spinfo1=(TextView)findViewById(R.id.spinfo1);
        spinfo2 = (TextView)findViewById(R.id.spinfo2);
        spinfo3 = (TextView)findViewById(R.id.spinfo3);

        jlbvname=getIntent().getStringExtra("jlbvname");
        jlbvnames= Service.BASE_URL+"yuejian/public/static/jlbvideo/"+getIntent().getStringExtra("jlbvnames");
        jlbvtime=getIntent().getStringExtra("jlbvtime");
        jlbjlname=getIntent().getStringExtra("jlbjlname");

//        spinfo_sp.setVideoURI(Uri.parse(jlbvnames));
//        MediaController mediaController = new MediaController(JlbSpInfoActivity.this);
//        spinfo_sp.setMediaController(mediaController);

        spinfo1.setText("名称:"+jlbvname);
        spinfo2.setText("上传时间:"+jlbvtime);
        spinfo3.setText("上传教练:"+jlbjlname);


        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//设置屏幕方向为横向
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);//设置全屏
        getWindow().setFormat(PixelFormat.TRANSLUCENT);//透明
        videoView=(VideoView)findViewById(R.id.spinfo_sp);

        path=jlbvnames;//获取视频全路径
        dialog=ProgressDialog.show(JlbSpInfoActivity.this, "视频加载中...", "请您稍候");//进度条

        Uri uri = Uri.parse(path);
        videoView.setMediaController(new MediaController(this));//媒体播放控制工具
        videoView.setVideoURI(uri);//设置视频路径
        videoView.setOnPreparedListener(new MyPlayerOnPreparedListener());//播放开始回调
        videoView.setOnCompletionListener( new MyPlayerOnCompletionListener());//播放完成回调
        videoView.requestFocus();// 让VideoView获取焦点
        videoView.start();//开始播放


    }

    @Override
    void initEvent() {
        spinfo_fh.setOnClickListener(this);

    }

    @Override
    void initDate() {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.spinfo_fh:
                finish();
                break;
        }
    }

    //自定义子类，监听视频准备好，消除加载对话框
    class MyPlayerOnPreparedListener implements MediaPlayer.OnPreparedListener {
        @Override
        public void onPrepared(MediaPlayer mp) {
            videoView.setBackgroundColor(Color.argb(0, 0, 255, 0));
            dialog.dismiss();
        }
    }
    //自定义子类，监听播放完成，显示完成
    class MyPlayerOnCompletionListener implements MediaPlayer.OnCompletionListener {

        @Override
        public void onCompletion(MediaPlayer mp) {
            Toast.makeText(JlbSpInfoActivity.this, "播放完成", Toast.LENGTH_SHORT).show();
            //getSupportActionBar().show();
        }
    }
}
